//
//  ViewController.m
//  myhuibao
//
//  Created by lijun on 13-2-4.
//  Copyright (c) 2013年 myhuibao. All rights reserved.
//

#import "BookViewController.h"
#import "BoxTableViewController.h"
#import "SmsViewController.h"
#import "LoginViewController.h"
#import "ASIHTTPRequest.h"
#import "ASIFormDataRequest.h"
#import "SBJson.h"
#import "config.h"
#import<QuartzCore/QuartzCore.h>
#import "LatestViewController.h"
//#import "MainTabViewController.h"
@interface BookViewController ()
@property (nonatomic, strong) PMCalendarController *pmCC;

@end

@implementation BookViewController
@synthesize mainView;
@synthesize tbTime;
@synthesize tbDate;
@synthesize tbDiningNumber;
@synthesize tbMemo;
@synthesize btBook;
@synthesize lbTitle;
@synthesize tbBoxType;
@synthesize pmCC;
@synthesize boxIds;
@synthesize viewBox;
@synthesize merchantName;
@synthesize showBox;
@synthesize otherView;
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    [self initDefault];
//    [self getTables];
    [self addCloseBar];
}
- (void)initDefault{
    tbDiningNumber.delegate = self;
    tbMemo.delegate = self;
    NSDate *curDate = [NSDate date];//获取当前日期
    if ([[[NSDate date] dateStringWithFormat:@"HH"]intValue]>=20) {
        curDate = [curDate dateByAddingDays:1];
    }
    tbDate.text = [NSString stringWithFormat:@"到店日期：%@", [curDate dateStringWithFormat:@"yyyy-MM-dd"]];
    NSString *d = [curDate dateStringWithFormat:@"yyyy-MM-dd"];
    if (![diningDate isEqualToString:d]) {
        diningDate = [d copy];
    }
    lbTitle.text = merchantName;
    //判读默认时间段
    if([[[NSDate date] dateStringWithFormat:@"HH"]intValue]<12
       ||[[[NSDate date] dateStringWithFormat:@"HH"]intValue]>=20)
    {
        diningTime = 2;
        diningHour = 12;
        diningMin = 0;
        _tfTime.text = @"12点";
        _tfMinute.text = @"00分";
        _selectedIndex = 2;
        _selectedIndex1=0;
//        tbTime.text = [NSString stringWithFormat:@"就餐时段： %@",@"中午11:00-2:00"];
    }else
    {
        diningTime = 4;
        diningHour = 18;
        diningMin = 0;
        _tfTime.text = @"18点";
        _tfMinute.text = @"00分";
        _selectedIndex = 6;
        _selectedIndex1=0;
//        tbTime.text = [NSString stringWithFormat:@"就餐时段： %@",@"晚上6:00-12:00"]; 
    }
    boxType = 0;
    
    //非协议和未开通包厢商户，不显示选择包厢按钮
    if(!showBox){
        viewBox.hidden = true;
        otherView.frame = CGRectMake(otherView.frame.origin.x,otherView.frame.origin.y-30,otherView.frame.size.width,otherView.frame.size.height);
        mainView.frame = CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y,mainView.frame.size.width,mainView.frame.size.height-40);

    }
    mainView.layer.cornerRadius=3;
    mainView.layer.borderWidth=1;
    mainView.layer.borderColor=LINE_COLOR.CGColor;
    [[mainView layer] setShadowOffset:CGSizeMake(1, 1)];
    [[mainView layer] setShadowRadius:1];
    [[mainView layer] setShadowOpacity:1];
    [[mainView layer] setShadowColor:LINE_COLOR.CGColor];
    
    otherView.layer.cornerRadius=3;
    otherView.layer.borderWidth=1;
    otherView.layer.borderColor=LINE_COLOR.CGColor;
    [[otherView layer] setShadowOffset:CGSizeMake(1, 1)];
    [[otherView layer] setShadowRadius:1];
    [[otherView layer] setShadowOpacity:1];
    [[otherView layer] setShadowColor:LINE_COLOR.CGColor];
    
    _vTime.layer.cornerRadius=3;
    _vTime.layer.borderWidth=1;
    _vTime.layer.borderColor= TEXTFIELD_COLOR.CGColor;
    _vMinute.layer.cornerRadius=3;
    _vMinute.layer.borderWidth=1;
    _vMinute.layer.borderColor= TEXTFIELD_COLOR.CGColor;
    if(_merchantType==1)
    {
        arrayTime = [NSMutableArray arrayWithObjects:
                      [NSDictionary dictionaryWithObjectsAndKeys:@"10点",@"text", @"10",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"11点",@"text", @"11",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"12点",@"text", @"12",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"13点",@"text", @"13",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"14点",@"text", @"14",@"id",nil],
                      //[NSDictionary dictionaryWithObjectsAndKeys:@"15点",@"text", @"15",@"id",nil],
                      //[NSDictionary dictionaryWithObjectsAndKeys:@"16点",@"text", @"16",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"17点",@"text", @"17",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"18点",@"text", @"18",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"19点",@"text", @"19",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"20点",@"text", @"20",@"id",nil],
                      nil];

    }
    else
    {
        arrayTime = [NSMutableArray arrayWithObjects:
                      [NSDictionary dictionaryWithObjectsAndKeys:@"8点",@"text", @"10",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"9点",@"text", @"11",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"10点",@"text", @"10",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"11点",@"text", @"11",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"12点",@"text", @"12",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"13点",@"text", @"13",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"14点",@"text", @"14",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"15点",@"text", @"15",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"16点",@"text", @"16",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"17点",@"text", @"17",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"18点",@"text", @"18",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"19点",@"text", @"19",@"id",nil],
                      [NSDictionary dictionaryWithObjectsAndKeys:@"20点",@"text", @"20",@"id",nil],
                      nil];

    }
    arrayMinute = [NSMutableArray arrayWithObjects:
                  [NSDictionary dictionaryWithObjectsAndKeys:@"00分",@"text", @"00",@"id",nil],
                  [NSDictionary dictionaryWithObjectsAndKeys:@"30分",@"text", @"30",@"id",nil],
                  nil];
//    if(_merchantType!=1)
//    {
//        viewBox.hidden=YES;
//        [otherView setFrame:CGRectMake(otherView.frame.origin.x, otherView.frame.origin.y-45, otherView.frame.size.width, otherView.frame.size.height)];
//    }
}

- (void) getTables{
    //异步请求
    NSURL *url = [NSURL URLWithString:url_boxType];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];

    [request setDelegate: self];
    [request startAsynchronous];

}
//下面是两个代理函数,当数据请求成功时会调用requestFinished，请求失败时（如网络问题或服务器内部错误）会调用requestFailed
- (void)requestFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    NSString *jsonStr = [request responseString];
    NSDictionary *dic = [jsonStr JSONValue];
    arrayBoxType = [dic valueForKey:@"data"];
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                          @"0",@"boxTypeID",@"不限",@"boxTypeDesc",nil];
    [arrayBoxType insertObject: dict atIndex:0];

//    NSLog(@"%@", arrayBoxType);
    //评论页面
    NSURL * url = [NSURL URLWithString:url_diningTime] ;
    request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];
    jsonStr = [request responseString];
    dic = [jsonStr JSONValue];
    arrayDiningTime = [dic valueForKey:@"data"];
    
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"%@",error);
}

- (void)viewDidUnload
{
    [self setTbBoxType:nil];
    [self setTbTime:nil];
    [self setTbDate:nil];
    [self setMainView:nil];
    [self setTbDiningNumber:nil];
    [self setTbMemo:nil];
    [self setBtBook:nil];
    [self setLbTitle:nil];
    [self setViewBox:nil];
    [self setOtherView:nil];
    [self setVTime:nil];
    [self setTfTime:nil];
    [self setVMinute:nil];
    [self setTfMinute:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title=@"包厢搜索";
    }
    return self;
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    //    if (theTextField == self.textField) {
    [theTextField resignFirstResponder];
    //    }
    return YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];
    
    switch ([allTouches count]) {
        case 1: {
            // potential pan gesture
            [self.tbDiningNumber resignFirstResponder];
        } break;
    }
}
- (IBAction)showBoxType:(id)sender {
    [tbDiningNumber    resignFirstResponder];
    BoxTableViewController  *view = [[BoxTableViewController alloc] initWithNibName:@"BoxTableViewController" bundle:nil];
    view.merchantId = _merchantId;
    view.diningDate = diningDate;
    view.diningHour = diningHour;
    view.diningMin = diningMin;
//    NSLog(@"%@",self.boxIds);
    view.diningTime = diningTime;
    view.delegatePassValue = self;
    view.selectedIds = self.boxIds;
    view.hidesBottomBarWhenPushed=YES;
	[self.navigationController pushViewController:view animated:YES];
}
#pragma mark - LeveyPopListView delegates
- (void)leveyPopListView:(LeveyPopListView *)popListView didSelectedIndex:(NSInteger)anIndex options:(NSArray *)_options didSelectedTypeIndex:(NSInteger)anTypeIndex
{
    switch (selectIndex) {
        case 1:{
            _selectedIndex = anIndex;
            _tfTime.text = [NSString stringWithFormat:@"%@",[[_options objectAtIndex:anIndex] objectForKey:@"text"]];
            
            diningHour = [[[_options objectAtIndex:anIndex] objectForKey:@"id"] intValue];
            break;
        }
        case 2:{
            _selectedIndex1 = anIndex;
            _tfMinute.text = [NSString stringWithFormat:@"%@",[[_options objectAtIndex:anIndex] objectForKey:@"text"]];
            
            diningMin = [[[_options objectAtIndex:anIndex] objectForKey:@"id"] intValue];
            break;
        }
        case 4:{
            tbTime.text = [NSString stringWithFormat:@"就餐时段： %@",[[arrayDiningTime objectAtIndex:anIndex] objectForKey:@"timeDesc"]];
            diningTime= [[[arrayDiningTime objectAtIndex:anIndex] objectForKey:@"timeID"] intValue];
            break;}
        case 5:{
            tbBoxType.text = [NSString stringWithFormat:@"包厢类型： %@",[[arrayBoxType objectAtIndex:anIndex] objectForKey:@"boxTypeDesc"]];
            boxType= [[[arrayBoxType objectAtIndex:anIndex] objectForKey:@"boxTypeID"] intValue];
            break;}
        
        default:
            break;
    }
}
- (void)leveyPopListViewDidCancel
{
    //edtCity.text = @"You have cancelled";
}


- (IBAction)doBack:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)showDiningTime:(id)sender {
    selectIndex = 4;
    LeveyPopListView *lplv = [[LeveyPopListView alloc] initWithTitle:@"请选择就餐时段..." options:arrayDiningTime];
    lplv.name = @"timeDesc";
    lplv.delegate = self;
    [lplv showInView:self.view animated:YES];
}


- (IBAction)showCanlendar:(id)sender {
    [tbDiningNumber    resignFirstResponder];
    self.pmCC = [[PMCalendarController alloc] init];
    pmCC.delegate = self;
    pmCC.mondayFirstDayOfWeek = YES;
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat : @"yyyy-MM-dd"];
    pmCC.period = [PMPeriod oneDayPeriodWithDate:[formatter dateFromString:diningDate]];
    
    [pmCC presentCalendarFromView:sender
         permittedArrowDirections:PMCalendarArrowDirectionAny
                         animated:YES];
    pmCC.allowsPeriodSelection = YES;
    /*[pmCC presentCalendarFromRect:[sender frame]
     inView:[sender superview]
     permittedArrowDirections:PMCalendarArrowDirectionAny
     animated:YES];*/
    [self calendarController:pmCC didChangePeriod:pmCC.period];

}

#pragma mark PMCalendarControllerDelegate methods

- (void)calendarController:(PMCalendarController *)calendarController didChangePeriod:(PMPeriod *)newPeriod
{
    tbDate.text = [NSString stringWithFormat:@"到店日期：%@", [newPeriod.endDate dateStringWithFormat:@"yyyy-MM-dd"]];
    NSString *d = [newPeriod.endDate dateStringWithFormat:@"yyyy-MM-dd"];
    if (![diningDate isEqualToString:d]) {
        diningDate = [d copy];
        [[calendarController view ] removeFromSuperview];
    }
}
//提交订单
- (IBAction)doBook:(id)sender {
    //判断是否登录会员
    int memberId = [[Config Instance] getMemberId];
    if(memberId == 0)
    {
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                      message:@"您还未登录，请先登录。"
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];

        LoginViewController  *view = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
        view.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:view animated:YES];
//        MainTabViewController *mainTabViewController;
//        mainTabViewController = [[MainTabViewController alloc] init];
//        [mainTabViewController selectViewController:3];
//        [self.view.window addSubview:mainTabViewController.view];

        return;
    }
    if(![self validateForm2]) return;
    NSURL *url = [NSURL URLWithString:url_order];
    ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
//    int memberId = [[Config Instance] getMemberId];
    [request setPostValue:[NSString stringWithFormat:@"%d",memberId] forKey:@"memberID"];
    [request setPostValue:[[Config Instance] getPassword] forKey:@"password"];
    [request setPostValue:[NSString stringWithFormat:@"%d",_merchantId] forKey:@"merchantID"];
    [request setPostValue:[NSString stringWithFormat:@"%d",_merchantType] forKey:@"merchantType"];
    [request setPostValue:[NSString stringWithFormat:@"%d",1] forKey:@"cityID"];
    [request setPostValue: tbDiningNumber.text forKey:@"diningNumber"];
    [request setPostValue: diningDate forKey:@"diningDate"];
//    [request setPostValue:[NSString stringWithFormat:@"%d",diningTime] forKey:@"diningTime"];
    [request setPostValue:[NSString stringWithFormat:@"%d",diningHour] forKey:@"diningHour"];
    if (diningMin==0) {
        [request setPostValue:@"00" forKey:@"diningMin"];
    }else
        [request setPostValue:[NSString stringWithFormat:@"%d",diningMin] forKey:@"diningMin"];
    if ([tbMemo.text isEqualToString:@"其他要求"]) 
        [request setPostValue:@"" forKey:@"memo"];
    else
        [request setPostValue: tbMemo.text forKey:@"memo"];
    [request setPostValue: @"4" forKey:@"orderFrom"];
    [request setPostValue: boxIds forKey:@"boxIDs"];

    [request startSynchronous];
    NSString *jsonStr = [request responseString];
    NSDictionary *dic = [jsonStr JSONValue];
    NSLog(@"%@",jsonStr);
    if([[dic valueForKey:@"status"] isEqualToString:@"SUCCESS"])
    {
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                      message:@"订单提交成功"
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];

        NSDictionary * data = [dic valueForKey:@"data"];
        SmsViewController  *view = [[SmsViewController alloc] initWithNibName:@"SmsViewController" bundle:nil];
        view.orderNo=[data valueForKey:@"orderNO"];
        NSString *str;
        if(_merchantType==1)
        {
            str=@"就餐";
        }
        else if(_merchantType==2)
        {
            str=@"欢唱";
        }
        else {
            str=@"小聚";
        }
        view.content = [[data valueForKey:@"inviteSMS"] stringByReplacingOccurrencesOfString:@"就餐" withString:str];
//        NSLog(@"%@",data);
        [btBook setTitle:@"订单已提交" forState:UIControlStateNormal];
        btBook.enabled=NO;
        view.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:view animated:YES];
//        [view release];
    }else{
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                      message:[dic valueForKey:@"log"] 
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
    }
     
//    SmsViewController  *view = [[SmsViewController alloc] initWithNibName:@"SmsViewController" bundle:nil];
//    view.hidesBottomBarWhenPushed=YES;
//    [self.navigationController pushViewController:view animated:YES];
//    [view release];
}
-(bool) validateForm{
    NSString *msg = @"";
    if(![self isPureInt:tbDiningNumber.text])
        msg = @"请输入正确的就餐人数";
    NSDate *curDate = [NSDate date];//获取当前日期
    int cur = [[curDate dateStringWithFormat:@"yyyyMMdd"]intValue];
    NSDateFormatter *formater = [[ NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyy-MM-dd"];
    NSDate *date=[formater dateFromString:diningDate];
    int dining = [[date dateStringWithFormat:@"yyyyMMdd"]intValue];
    if(cur>dining)
        msg =[ msg stringByAppendingFormat:@"\n%@",@"到店时间不能在当前时间之前" ];
    //当前时间
    if (cur==dining) {
            cur = [[curDate dateStringWithFormat:@"HH"]intValue];
        switch (diningTime) {
            case 1:
                if (cur>=11) {
                    msg =[ msg stringByAppendingFormat:@"\n%@",@"到店时段不能在当前时间之前" ];
                }
                break;
            case 2:
                if (cur>=14) {
                    msg =[ msg stringByAppendingFormat:@"\n%@",@"到店时段不能在当前时间之前" ];
                }
                break;
            case 3:
                if (cur>=18) {
                    msg =[ msg stringByAppendingFormat:@"\n%@",@"就餐时段不能在当前时间之前" ];
                }
                break;
//            case 4:
//                if (cur<6) {
//                    msg =[ msg stringByAppendingFormat:@"\n%@",@"就餐时段不能在当前时间之前" ];
//                }
//                break;
            default:
                break;
        }
    }
    if(![msg isEqualToString:@""]){
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                      message:msg
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
        return false;
    }
    return true;
}
-(bool) validateForm2{
    NSString *msg = @"";
    if(![self isPureInt:tbDiningNumber.text])
        msg = @"请输入正确的就餐人数";
    if([tbDiningNumber.text intValue]>10000)
        msg = @"就餐人数超长";
    NSDate *curDate = [NSDate date];//获取当前日期
    int cur = [[curDate dateStringWithFormat:@"yyyyMMdd"]intValue];
    NSDateFormatter *formater = [[ NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyy-MM-dd"];
    NSDate *date=[formater dateFromString:diningDate];
    int dining = [[date dateStringWithFormat:@"yyyyMMdd"]intValue];
    if(cur>dining)
        msg =[ msg stringByAppendingFormat:@"\n%@",@"就餐时间不能在当前时间之前" ];
    //当前时间
    if (cur==dining) {
        cur = [[curDate dateStringWithFormat:@"HHmm"]intValue];
        int select = [[NSString stringWithFormat:@"%d%@",diningHour,diningMin==0?@"00":@"30"] intValue];
        if (cur>select) {
            msg =[ msg stringByAppendingFormat:@"\n%@",@"就餐时间不能在当前时间之前" ];
        }
    }
    if(![msg isEqualToString:@""]){
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                      message:msg
                                                     delegate:nil
                                            cancelButtonTitle:@"确定"
                                            otherButtonTitles:nil];
        [alert show];
        return false;
    }
    return true;
}

- (BOOL)isPureInt:(NSString *)string{
    //包含空格
    NSRange range = [string rangeOfString:@" "];
    if (range.location!=NSNotFound) {
        return false;
    }
    //小于等于0
    if ([string intValue]<=0) {
        return false;
    }
    NSScanner* scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}
//实现传参协议的方法
#pragma mark UIViewPassValueDelegate mothod
- (void)passBoxNames:(NSString *)boxNames withIds:(NSString *) Ids
{
    self.tbBoxType.text = [NSString stringWithFormat:@"选择包厢：%@",boxNames];
    self.boxIds = Ids;
    
//    NSLog(@"%@",boxIds);

}
- (void)addCloseBar{
    UIToolbar * topView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
    [topView setBarStyle:UIBarStyleDefault];
    
    UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
    NSArray * buttonsArray = [NSArray arrayWithObjects:btnSpace, doneButton, nil];
    
    [topView setItems:buttonsArray];
    [tbMemo setInputAccessoryView:topView];
}
-(IBAction)dismissKeyBoard
{
    //    [commentDeatil resignFirstResponder];
    NSTimeInterval animationDuration = 0.30f;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, self.view.frame.size.height);
    self.view.frame = rect;
    [UIView commitAnimations];
    [tbMemo resignFirstResponder];
}
- (void)textViewDidBeginEditing:(UITextView *)textView{
    float height = -90;
    CGRect frame = self.view.frame;
    frame.origin.y=height;
    [UIView beginAnimations:@"Curl"context:nil];//动画开始
    [UIView setAnimationDuration:0.30];
    [UIView setAnimationDelegate:self];
    [self.view setFrame:frame];
    [UIView commitAnimations];
    if ([tbMemo.text isEqualToString:@"其他要求"]) {
        tbMemo.text = @"";
    }
}
- (IBAction)showTime:(id)sender {
    [tbDiningNumber    resignFirstResponder];
        selectIndex = 1;
        LeveyPopListView *lplv = [[LeveyPopListView alloc] initWithTitle:@"请选择时间" options:arrayTime fullHeight:50 ];
        lplv.name = @"text";
        lplv.selectedIndex = _selectedIndex;
        lplv.delegate = self;
        [lplv showInView:self.view animated:YES];

}
- (IBAction)showMinute:(id)sender {
    [tbDiningNumber    resignFirstResponder];
    selectIndex = 2;
    LeveyPopListView *lplv = [[LeveyPopListView alloc] initWithTitle:@"请选择时间" options:arrayMinute fullHeight:50 ];
    lplv.name = @"text";
    lplv.selectedIndex = _selectedIndex1;
    lplv.delegate = self;
    [lplv showInView:self.view animated:YES];
}

@end
